package com.zc.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zc.dao.IFaultDao;
import com.zc.domain.DoubleListData;
import com.zc.domain.FaultItem;
import com.zc.domain.FaultStatisticsItem;
import com.zc.service.FaultService;

@Service(value="faultService")
public class FaultServiceImpl implements FaultService{
	@Autowired
	private IFaultDao faultDao;
	
	@Override
	public List<FaultItem> getCurFault() {
		return faultDao.getCurFault();
	}
	@Override
	public List<FaultItem> getAllFault(String channel) {
		return faultDao.getAllFault(channel);
	}
	@Override
	public List<FaultStatisticsItem> getCurFaultStat(String channel, String beginDate) {
		return faultDao.getCurFaultStat(channel, beginDate);
	}
	@Override
	public List<FaultStatisticsItem> daySelect(String channel, String beginDate) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date=null;
		try {
			date=sdf.parse(beginDate);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		Calendar c = Calendar.getInstance();  
        c.setTime(date);  
        c.add(Calendar.DAY_OF_MONTH, 1);
        String endDate=sdf.format(c.getTime());
		return faultDao.select(channel, beginDate, endDate);
	}
	@Override
	public List<FaultStatisticsItem> monthSelect(String channel, String beginDate) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); 
		Date date=null;
		try {
			date=sdf.parse(beginDate);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		Calendar c = Calendar.getInstance();  
        c.setTime(date);  
        c.add(Calendar.MONTH, 1);
        String endDate=sdf.format(c.getTime());
		return faultDao.select(channel, beginDate, endDate);
	}
}
